# -*- coding: utf-8 -*-

from __future__ import print_function
import logging
import random
import time

import grpc

from DeepFmApi_pb2 import DeepRequest
from DeepFmApi_pb2_grpc import DeepFmServiceStub


def run():
  print("client server start...")
  with grpc.insecure_channel('localhost:50000') as channel:
    stub = DeepFmServiceStub(channel)
    print("获取stub", stub)
    for i in range(10000):
      callTest(stub)


def callTest(stub):
  """
  """
  startTime = int(round(time.time() * 1000))
  version = random.randint(0, 10) * 100
  response = stub.test(
      DeepRequest(
          model_name="testModel",
          model_version=version,
          data=DeepRequest.Data(
              keys=["1", "2", "3"],
              features=[
                DeepRequest.FloatArray(value=[1.0, 2.0, 3.0]),
                DeepRequest.FloatArray(value=[2, 3, 4])
              ]
          )
      )
  )
  cost = int(round(time.time() * 1000)) - startTime
  print("服务端返回数据:", response.message, response.code, cost)


if __name__ == "__main__":
  logging.basicConfig()
  run()
